#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include "qzodiac.h"
#include "ihttpclient.h"
#include <QtCore/QStringList>
#include <QtCore/QThread>
#include <QtGui/QAction>
#include <QtGui/QMainWindow>
#include "ui_mainwindow.h"


/**
 * This class implements a thread to retrieve astrology date
 *
 * @author gonwan (gonwan@gmail.com)
 * @version 1.0
 */
class GoThread : public QThread
{
    Q_OBJECT

public:
    /**
     * Constructor
     * @param dtDate The date of current day
     * @param idxZodiac The zodiac index of current day
     */
    GoThread(const QDate &dtDate, const QZodiac::ZodiacIndex &idxZodiac);
    /**
     * Destructor
     */
    virtual ~GoThread();

protected:
    /**
     * Override
     * This function do the real job.
     * It downloads the web page and parses it.
     */
    void run();

private:
    /** The date of current day */
    QDate m_dtDate;
    /** The zodiac value of current day */
    QZodiac::ZodiacIndex m_idxZodiac;
    /** The Http client handle */
    IHttpClient *m_pHttpClient;

signals:
    /**
     * This signal is used to show message
     * @param strMessage The message to show
     */
    void showMessage(const QString &strMessage);

};


/**
 * This class represents the main window
 *
 * @author gonwan (gonwan@gmail.com)
 * @version 1.0
 */
class MainWindow : public QMainWindow, public Ui::MainWindow
{
    Q_OBJECT

public:
    /**
     * Constructor
     * It sets up UI and does initialization
     * @param parent The parent widget
     */
    MainWindow(QWidget *parent = 0);

protected:
    /**
     * Override
     * This function terminated the go thread before exiting.
     * @param event The close event
     */
    void closeEvent(QCloseEvent *event);

private:
    /**
     * This function initialize the class
     * It sets window size and fill in data in controls.
     * @return true if success
     */
    bool init();

    /** The go thread */
    GoThread *m_goThread;

public slots:
    /**
     * This slot set the content to display
     * @param strContent The content to display
     */
    void setContent(const QString &strContent);

private slots:
    /**
     * This slot is invoked when "go" button is pressed
     */
    void go();
    /**
    * This slot shows the about window
    */
    void about();
    /**
     * This slot shows the proxy setting window
     */
    void proxy();

private:
    /** Help function to stop the go thread */
    void stop();
    QAction *proxyAct;
    QAction *aboutAct;

};


#endif
